package com.xy.novelmanagement.service.impl;

import com.xy.model.AdminUser;
import com.xy.novelmanagement.mapper.UserMapper;
import com.xy.novelmanagement.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl  implements ILoginService {
		@Autowired
		private UserMapper mapper;
		@Override
		public int login(AdminUser user) {
				int num = 3;
				try {
						if(user==null){
								return 3;
						}
						int count = mapper.checkUser(user);
						if(count==1){
								int success = mapper.login(user);
								if(success==1){
										return 1;
								}else {
										return 2;
								}
						}
				} catch (Exception e) {
						e.printStackTrace();
						return 4;
				}
				return 3;
		}

		@Override
		public AdminUser getAdminUser(String username) {
				AdminUser adminUser=null;

				try {
						adminUser = mapper.getAdminUser(username);
				} catch (Exception e) {
						e.printStackTrace();
				}
				return adminUser;
		}
}
